package servlet;

import dao.SearchDao;
import dao.daoimpl.SearchDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name="SearchSubfieldServlet",urlPatterns = "/SearchSubfieldServlet")
public class SearchSubfieldServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");/*防止乱码*/
        String content=request.getParameter("searchArticleSubfield");/*获取搜索内容*/
        SearchDao searchDao=new SearchDaoImpl();/*搜索接口的实现类*/
        try {
            request.getSession().setAttribute("searchArticleResult",searchDao.subfieldSearch(content));/*返回结果*/
        }catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
    }
}
